package com.technology.education.ui.common.goods

import android.view.Gravity
import android.widget.ImageView
import com.angcyo.dsladapter.dpi
import com.angcyo.dsladapter.dslItem
import com.technology.education.R
import com.technology.education.base.BaseRecyclerTopBarFragment
import com.technology.education.data.model.GoodsOrderDetailModel
import com.technology.education.dslitem.ItemColumnTitleText
import com.technology.education.dslitem.ItemSingleText
import com.technology.education.ext.getColor
import com.technology.education.ext.loadImage
import me.hgj.jetpackmvvm.ext.parseState
import me.hgj.jetpackmvvm.util.get

/**
 *@author:create by BZY
 *Date: 2022/4/2 09
 * 兑换商品订单详情
 */
class GoodsOrderDetailFragment : BaseRecyclerTopBarFragment<GoodsOrderDetailViewModel>() {
    override fun initViews() {
        setTitle("确定订单")
        mViewModel.orderId = arguments?.get("id", "") ?: ""
    }

    override fun lazyLoadData() {
        loading()
    }

    override fun createObserver() {
        mViewModel.result.observe(this) {
            parseState(it, onSuccess = { it ->
                setUI(it)
            }, onError = {
                loadError()
            })
        }
    }

    private fun setUI(it: GoodsOrderDetailModel) {
        renderAdapter {
            dslItem(R.layout.item_goods_order_confirm)
            dslItem(R.layout.item_goods_order_info) {
                itemBindOverride = { itemHolder, _, _, _ ->
                    itemHolder.tv(R.id.tv_name)?.text = it.pointGoodsName
                    itemHolder.tv(R.id.tv_info)?.text = it.pointGoodsDescription
                    itemHolder.tv(R.id.tv_score)?.text = "${it.pointGoodsPrice}积分"
                    itemHolder.tv(R.id.tv_convert)?.text = "x${it.pointGoodsNum}"
                    itemHolder.v<ImageView>(R.id.iv_goods)?.apply {
                        loadImage(it.pointGoodsImage, this)
                    }
                }
            }

            dslItem(ItemSingleText("收货地址", itemSpan = -1)) {
                style.lineHeight=0
                style.bottomPadding=0
                style.isBold = true
            }
            dslItem(ItemSingleText("${it.name}  ${it.phone}")) {
                style.titleTextSize = 14f
                style.bottomPadding = 0
                style.lineHeight=0
                style.isBold = true
            }
            dslItem(ItemSingleText(it.addressStr)) {
                style.titleTextSize = 14f
                style.titleTextColor = R.color.text_m
                style.topPadding=6
            }

            dslItem(ItemColumnTitleText("订单号", content = it.id)) {
                style.titleTextColor = R.color.text_m
                style.contentTextColor = R.color.text_m
                style.contentGravity = Gravity.RIGHT
                style.lineHeight = 0

            }
            dslItem(ItemColumnTitleText("订单时间", content = it.placeTime)) {
                style.titleTextColor = R.color.text_m
                style.contentTextColor = R.color.text_m
                style.contentGravity = Gravity.RIGHT
                style.lineHeight = 0
                style.topPadding = 0
            }
            dslItem(ItemColumnTitleText("积分", content = "${it.pointGoodsAmount}积分")) {
                style.titleTextColor = R.color.text_m
                style.contentTextColor = R.color.text_m
                style.contentGravity = Gravity.RIGHT
                style.lineHeight = 0
                style.topPadding = 0
            }
        }
    }
}